<?php

namespace App\Http\Middleware;

use App\Traits\ReponseJson;
use Closure;

class BeforeLogin
{
    use ReponseJson;

    /**
     * 登錄前置中間件-注入登錄需要的client秘鑰
     * @param          $request
     * @param \Closure $next
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function handle($request, Closure $next)
    {
        $input = array_only($request->all(), ['mobile']);
        $request->merge(config('passport.proxy'));
        $request->merge(['username' => $input['mobile'] ?? '']);
        return $next($request);
    }
}
